home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- /* This program computes the LU decomposition of a matrix, with partial
- * pivoting. The last row of A contains pivoting information - what
- * row was swapped with at each iteration of the algorithm. */
-
- #define P 6
- #define N 14
-
- #include "dino.h"
-
- environment node[P:id] {
-
- #include <math.h>
- #include <stdio.h>
-
- composite plu (a)
-
- double distributed a[N+1][N] map WrapCol;
-
- /* ==> Declares the variable a to be mapped
- by columns to the processors, but in
- a wrap fashion, so that each processor
- gets columns id, id+P, id+2P, ... */
-
- {
- int i, j, k; /* Looping variables */
- double piv; /* Value of the pivot */
- int pivrow; /* Index of the pivot */
- double temp; /* Temporary */
-
- double distributed m[N+1] map all; /* Holds the multipliers */
-
- /* ==> Illustrates the declaration of local
- distributed data within a composite
- procedure. */
-
- /* Loop through the passes of the algorithm */
- for (i = 0; i < N; i++) {
-
- /* Check to see if we have the column for this iteration */
- if (i % P == id) {
- /* Select the pivot row */
- piv = fabs (a[i][i]);
- pivrow = i;
- for (j = i + 1; j < N; j++)
- if (fabs (a[j][i]) > piv) {
- piv = fabs (a[j][i]);
- pivrow = j;
- }
-
- /* Swap in the pivot column */
- temp = a[pivrow][i]; a[pivrow][i] = a[i][i]; a[i][i] = temp;
-
- /* Compute the multipliers */
- for (j = i + 1; j < N; j++)
- a[j][i] /= a[i][i];
-
- /* Put the pivot row into a, in preparation for sending */
- a[N][i] = pivrow;
-
- /* Send out the data to the multiplier vectors on all processors */
- m[<i+1,N>] = a[<i+1,N>][i];
-
- /* ==> Ranges may be used in assignment
- statements to perform array
- assignments. */
-
- m[<i+1,N>]# {node[] - node[id]} = m[<i+1,N>];
-
- /* ==> Explicit sends are indicated by putting
- an environment set in braces after the
- "#" sign. */
-
- /* ==> Sends to every node but itself through
- the use of the "-" operator in the
- environment expression. */
- }
-
- else
-
- /* Receive the multiplier data */
- m[<i+1,N>] = m[<i+1,N>]# {node[i%P]};
-
- /* Now, we're ready to do the elimination and pivoting at the same time */
- pivrow = m[N];
- for (j = id; j < N; j += P)
- if (j > i) {
- temp = a[i][j]; a[i][j] = a[pivrow][j]; a[pivrow][j] = temp;
- for (k = i+1; k < N; k++)
- a[k][j] -= m[k] * a[i][j];
- }
- }
- }
-
- }
-
- environment host {
-
- double a[N+1][N]; /* Holds the matrix */
-
- void main () {
-
- int i, j; /* Looping variables */
-
- /* Set up the test matrix */
- for (i = 0; i < N; i++) {
- for (j = 0; j < N; j++)
- a[i][j] = (i + 1) * (j + 1);
- a[i][i]++;
- }
-
- /* Output an initial message */
- printf ("Starting LU decomposition...\n\n");
-
- /* Call the composite procedure */
- plu (a[][])#;
-
- /* Printout the results */
- printf ("Result is...\n");
- for (i = 0; i < N; i++) {
- for (j = 0; j < N; j++)
- printf ("%6.1f", a[i][j]);
- printf ("\n");
- }
-
- printf ("\nWith pivots...\n");
- for (j = 0; j < N; j++)
- printf ("%.2f ", a[N][j]);
- printf ("\n");
-
- }
- }
-